<?php

/**
   {banner type=type_id [forceSize=false]}
*/

function show_banner($params) 
{ 
	$banner = new Banner($params['type']);
	$banner->onDisplay();
	if ($banner->exists())
	{
		$image = $banner->image();
		$width = $banner->width();
		$height = $banner->height();

		if (array_key_exists('forceSize',$params) && $params['forceSize'])
		{
			$thumbnail = new Thumbnail($banner->path(),$banner->width(),$banner->height());
			$image = $thumbnail->url();
			$width = $thumbnail->width();
			$height = $thumbnail->height();
		}
		else
		{
			$img = Image::loadFromFile($banner->path());
			$width = $img->width();
			$height = $img->height();
		}
		
		return 
			"<a href='{$banner->url()}' target='{$banner->target()}'>
				<img src='{$image}' alt='{$banner->name()}' title='{$banner->name()}' width='{$width}' height='{$height}' />
			</a>";
	}
	return '';	
} 

$smarty->register_function("banner", "show_banner"); 

?>